package cn.iocoder.yudao.module.trade.order.vo;

import cn.iocoder.yudao.module.api.trade.delivery.enums.DeliveryTypeEnum;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.AssertTrue;
import lombok.Data;

import java.util.Objects;

@Schema(description = "用户 App - 交易订单创建 Request VO")
@Data
@Valid
public class AppTradeOrderCreateReqVO extends AppTradeOrderSettlementReqVO {

    @Schema(description = "备注", example = "这个是我的订单哟")
    private String remark;

    @SuppressWarnings("unused")
    @AssertTrue(message = "地址不完善")
    @JsonIgnore
    public boolean isDeliveryValid() {
        // 无需配送
        if (getDeliveryType() == null || Objects.equals(getDeliveryType(), DeliveryTypeEnum.NONE.getType())) {
            return true;
        }
        // 到店核销
        if (Objects.equals(getDeliveryType(), DeliveryTypeEnum.VERIFY.getType())) {
            return true;
        }
        // 到店自提需要选择自提门店
        if (Objects.equals(getDeliveryType(), DeliveryTypeEnum.PICK_UP.getType())) {
            return getPickUpStoreId() != null && getPickUpStoreId() > 0;
        }
        // 其他配送类型/服务方式需要选择收货地址/上门服务地址
        return getAddressId() != null && getAddressId() > 0;
    }

}
